<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta
        name="viewport"
        content="width=device-width, initial-scale=1.0"
    >
    <title>postMessage B</title>
</head>

<body>
    <script>
        // 监听A发送过来的数据
        window.onmessage = function (ev) {
            console.log('B打印A发送的数据: ' + ev.data);
            // 向A发送数据
            ev.source.postMessage('Hello! this is B.html', '*');
        }
    </script>
</body>

</html>